package cn.kbyue.redisdemo.controller;

import cn.kbyue.redisdemo.entity.Product;
import cn.kbyue.redisdemo.service.ProductService;
import org.springframework.aop.framework.AopContext;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Caching 注解测试
 * @author xlang
 * @date 2023/3/21 15:45
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping("{id}")
    public ResponseEntity<Product> getProduct(@PathVariable("id") Long id) {
        Product product = productService.getItem(id);
        return ResponseEntity.ok(product);
    }

    @PostMapping("/update")
    public ResponseEntity<String> update(@RequestBody Product product) {
        int update = productService.update(product.getId(), product);
        return ResponseEntity.ok("操作成功");
    }

    @DeleteMapping("{id}")
    public ResponseEntity<String> delete(@PathVariable("id") Long id) {
        int delete = productService.delete(id);
        return ResponseEntity.ok("删除成功");
    }

}
